from PyQt5.QtWidgets import QMessageBox

from src.admin.InsertFine import Ui_Form
from PyQt5 import QtWidgets


class InsertFine_Win(QtWidgets.QMainWindow,Ui_Form):
    def __init__(self,mydb, parent=None):
        super(InsertFine_Win, self).__init__(parent=parent)
        #ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID('')
        #self.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
        #self.setWindowIcon(icon)
        self.setupUi(self)
        self.CalcuSignal=False
        self.mydb=mydb

    def myOut(self):
        self.hide()


    def getmydb(self,mydb):
        self.mydb=mydb


    def myCalcu(self):
        myselect_Toy="select 标准价格,损旧等级 from 玩具个体表 where 玩具编号= "+self.lineEdit_2.text()
        myselect_FK="select 罚款基数 from 罚款表 where 罚款种类号= "+self.lineEdit_3.text()
        try:
            mycur = self.mydb.cursor()
            mycur.execute(myselect_Toy)
        except Exception as a:
            self.label_7.setText(str(0))
            QMessageBox.critical(self, '错误', '玩具信息不正确')
        else:
            result_Toy = mycur.fetchall()
            try:
                mycur.execute(myselect_FK)
                result_FK = mycur.fetchall()
            except Exception as a:
                self.label_7.setText(str(0))
                QMessageBox.critical(self, '错误', '罚款种类不正确')
            else:
                if len(result_Toy) == 0:
                    self.label_7.setText(str(0))
                    QMessageBox.critical(self, '错误', '玩具信息不正确')
                elif len(result_FK) == 0:
                    self.label_7.setText(str(0))
                    QMessageBox.critical(self, '错误', '罚款种类不正确')
                else:
                    result = result_Toy[0][0] * (1 - (result_Toy[0][1] / 10)) * result_FK[0][0] / 10
                    self.label_7.setText(str(result))
                    self.CalcuSignal=True